<?php
/**
 * Created by JetBrains PhpStorm.
 * User: manuel.moyano
 * Date: 17/09/13
 * Time: 10:35
 * To change this template use File | Settings | File Templates.
 */

class languages
{

    protected $table = "languages";

    public $id = 0;
    public $name;
    public $active;

    public $create_date;
    public $create_user;
    public $update_date;
    public $update_user;

    function languages(){
        $this->con = new DataBase();
    }

    function open($query)
    {
        if(!is_array($query)){

            if(is_numeric($query))
                $result = $this->con->genericQuery("select * from " . $this->table . " where id = '$query'");    

            $query = $result[0];
                
        }
        if (count($query) == 0)
            return false;
        else {
            $this->id = $query['id'];
            $this->name = $query['name'];
            $this->active = $query['active'];
            
            $this->create_date = $query['create_date'];
            $this->create_user = $query['create_user'];
            $this->update_date = $query['update_date'];
            $this->update_user = $query['update_user'];

            return true;
        }
    }

      function list_languages()
    {
        $query = $this->con->genericQuery("select * from " . $this->table . " where active = 1");

        $objReturn = array();

        foreach ($query as $value) {
            $language = new languages();
            $language->open($value);
            $objReturn[] = $language;
        }

        return $objReturn;
    }
}